﻿// Programmer: JR Padfield
// Description: 
// Version: 1
// Date: 

﻿using System.Collections.Generic;
using TheWorldLibrary.TileEngine;
using TheWorldLibrary.Characters;
using TheWorldLibrary.Items;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace TheWorldLibrary.Worlds
{
    public class Level
    {
        #region Field Region

        readonly TileMap _map;
        readonly List<Character> _characters;
        readonly List<ItemSprite> _chests;
        private readonly Attributes[,] _attribute;
        private int _maxHeight;
        private int _maxWidth;

        #endregion

        #region Property Region

        public TileMap Map
        {
            get { return _map; }
        }

        public List<Character> Characters
        {
            get { return _characters; }
        }

        public List<ItemSprite> Chests
        {
            get { return _chests; }
        }        

        public int MaxHeight
        {
            get { return _maxHeight; }
            set { _maxHeight = value; }
        }

        public int MaxWidth
        {
            get { return _maxWidth; }
            set { _maxWidth = value; }
        }

        #endregion

        #region Constructor Region

        public Level(TileMap tileMap, int mapWidth, int mapHeight)
        {
            _map = tileMap;
            _characters = new List<Character>();
            _chests = new List<ItemSprite>();
            _attribute = new Attributes[mapHeight, mapWidth];
        }

        public Level(TileMap tileMap)
        {
            _map = tileMap;
            _characters = new List<Character>();
            _chests = new List<ItemSprite>();
        }

        #endregion

        #region Method Region

        public void Update(GameTime gameTime)
        {
            foreach (ItemSprite sprite in _chests)
                sprite.Update(gameTime);
        }

        public void Draw(GameTime gameTime, SpriteBatch spriteBatch, Camera camera)
        {
            _map.Draw(spriteBatch, camera);

            foreach (ItemSprite sprite in _chests)
                sprite.Draw(gameTime, spriteBatch);
        }

        public void SetAttributeTile(int x, int y, int att)
        {
            _attribute[y, x] =new Attributes(att);
        }

        public Attributes GetAttribute(int x, int y)
        {
            return _attribute[y, x];
        }

        #endregion
    }
}

